package org.eenie.appseed.ui.counter

import androidx.activity.viewModels
import com.blankj.utilcode.util.LogUtils
import org.eenie.appseed.R
import org.eenie.appseed.databinding.ActivityCounterBinding
import org.eenie.core.base.viewmodel.BaseBindingViewModelActivity
import org.eenie.core.ext.onClick
import org.eenie.core.ext.transact

class CounterActivity : BaseBindingViewModelActivity<ActivityCounterBinding, CounterState, CounterViewModel>() {

    override fun initUI() {
        binding.apply {
            btnSub.onClick {
                viewModel.sub()
            }

            btnAdd.onClick {
                viewModel.increment()
            }
        }
    }

    override fun providerViewModel() = viewModels<CounterViewModel>().value

    override fun renderUI(state: CounterState) {
        when (state) {
            is CounterState.OnCountChange -> {
                binding.tvCountActivity.text = state.value.toString()
            }

            else -> {

            }
        }
    }

    override fun providerBinding() = ActivityCounterBinding.inflate(layoutInflater)
}